<!--<?php print <<<EOT
-->
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
/*a link 基本连接颜色*/
a{text-decoration:none;color:#003399;}
a:hover,.alink a,.link{text-decoration:underline;}
body{ font-size:12px; color:#444;line-height:1.5;}
.pdD{padding:.3em .5em}
.pd5{padding:0 5px;}
.pd15{padding:0 15px;}
/*select*/
.dropdown {outline:none; padding-bottom:2px}
.dropdown h4{cursor:default; text-indent:5px;}
.dropdown * {-moz-user-select:none;}
.dropdown h4.over {}
.dropdown div {}
.dropdown span {position:absolute;}
.dropdown ul{position:absolute;display:none;}
.dropdown ul li{text-indent:5px;}
.dropdown ul li.over{}
.dropselectbox {background:#fff;}
.dropdown {float:left;}
.dropdown button{display:block;text-align:left;margin:0;padding-left:5px;height:21px; font:12px Arial, Helvetica, sans-serif; border:solid 1px #AAA;background:url(u/images/droparrow.gif) no-repeat right center;}
.dropdown button.over{border-color:#369; background-image:url(u/images/droparrowover.gif);}
.dropdown button.current{border-color:#003;}
.dropdown ul{border:1px solid #AAA; background:#FFF;}
.dropdown ul li{background:#FFF;height:19px;display:block;cursor:default;font:400 12px/19px Arial, Helvetica, sans-serif;}
.dropdown ul li.over{background:#369; color:#FFF;}
</style>
<link rel="stylesheet" type="text/css" href="images/pw_core.css" />
<link rel="stylesheet" type="text/css" href="images/post/c_editor/editor.css" />
</head>
<body>
<div>
	<div class="popTop">
		<a href="javascript:window.parent.document.getElementById('pw_box').style.display = 'none';" class="adel">删除</a>
		<ul id="tabs" class="cc">
			<li class="current" title="album"><a href="javascript:;">相册图片</a></li>
			<li title="local"><a href="javascript:;">本地图片</a></li>
			<li title="network"><a href="javascript:;">网络图片</a></li>
		</ul>
	</div>

<!-- 
EOT;
	if(count($photos) > 0){
		$photoListDisplay = 'style="display:"';
		$noPhotoListDisplay = 'style="display:none"';
	}else{
		$photoListDisplay = 'style="display:none"';
		$noPhotoListDisplay = 'style="display:"';	
	}
		print <<<EOT
-->
    <div class="tabsctn p10">
		<div class="mb5"><select id="aidsel_info2" name="aid" onChange="ajaxLoadPhotos(this);">
<!--
EOT;
			foreach($albums as $album){
				$selectedHtml = $album['aid'] == $aid?' selected': '';
				print <<<EOT
-->			
				<option value="{$album['aid']}" {$selectedHtml}>{$album['aname']}</option>
<!--
EOT;
}
print <<<EOT
-->
			</select></div>
			<div class="c"></div>
			<div class="popupList" id="noPhotoList" {$noPhotoListDisplay}>
				<div class="p10">该相册还没有照片，请先 <a href="apps.php?q=photos&a=upload&job=flash" class="s4" target="_blank">上传</a></div>
			</div>
			<div class="popupList" id="photoList" {$photoListDisplay}>
				<div id="J_popupList">
					<ul id="album" class="popUlone">
<!--
EOT;
					foreach($photos as $photo){
						$lastpos = strrpos($photo['path'],'/');
						$photo['o_path'] = preg_match('/^s_/',basename($photo['path']))?dirname($photo['path']).'/'.substr($photo['path'],$lastpos+3) : $photo['path']; /* original path*/
						print <<<EOT
-->		
					<li><span></span><label><img data_src="{$photo['path']}" width="56" height="56" /><input type="checkbox" value="{$photo['o_path']}" /></label></li>
<!--
EOT;
					}
	print <<<EOT
-->
	
					</ul>
				</div>
		</div>
	</div>
<!--
EOT;
if ($o_photos_gdcheck) {
	$popUpcontheight = "height:215px";
}print <<<EOT
-->
    <div class="tabsctn popUpcont" style="display:none; $popUpcontheight">
    <form action="uploadPhoto" method="post" id="uploadPhoto" enctype="multipart/form-data">
		<div class="mb10"><input name="photo" accept="image/*" size="40" type="file" class="input" /></div>
		<div class="mb10"><div class="mb5">将该图片上传至相册 </div>
		<div class="dropdown mr10" id="album_drop">
		<select id="album_list" class="" name="aid">
<!--
EOT;
		foreach($albums as $album){
			$selectedHtml = $album['aid'] == $aid?' selected': '';
			print <<<EOT
-->				
			<option value="{$album['aid']}" {$selectedHtml}>{$album['aname']}</option>
<!--
EOT;
		}
		print <<<EOT
-->			
		</select></div>
		<span class="bt2"><span><button type="button" onClick="getObj('create_album_div').style.visibility='visible'">+创建新相册</button></span></span></div>
		<div id="create_album_div" style="visibility:hidden;">
		<table class="vt">
			<tr class="tr3">
				<td width="80">相册名</td>
				<td><input id="albumName" type="text" class="input mb5 input_wa" /></td>
			</tr>       
<!--
EOT;
if ($o_photos_gdcheck) {print <<<EOT
-->
		<tr class="tr3">
			<td>认证码:</td>
			<td><input class="input mr5 mb5" onFocus="showCK();" type="text" name="gdcode" id="gdcode" style="width:50px;" tabindex="3"  /><img id="ckcode" style="cursor:pointer;display:none;margin-bottom:5px; vertical-align:top;" onClick="this.src='ck.php?nowtime='+new Date().getTime();" alt="看不清楚，换一张" />
<script language="JavaScript">
function showCK(){
	getObj('ckcode').style.display="";
	if (getObj('ckcode').src.indexOf('ck.php') == -1) {
		getObj('ckcode').src = 'ck.php?nowtime=' + new Date().getTime();
	}
}
</script>
			</td>
		</tr>
<!--
EOT;
}if($o_photos_qcheck){print <<<EOT
-->
		<tr class="tr3">
			<td>验证问题</td>
			<td>
			<div>{$db_question[$qkey]}
<!--
EOT;
if($showq){print <<<EOT
-->
			<p>正确答案:{$db_answer[$qkey]}</p>
<!--
EOT;
}print <<<EOT
-->
			</div>
			<input class="input mb5 input_wa" name="qanswer" id="qanswer" tabindex="7" />
			<input type="hidden" name="qkey" id="qkey" value="$qkey" />
			</td>
		</tr>
<!--
EOT;
}print <<<EOT
-->
		<tr>
			<td>&nbsp;</td>
			<td><span class="btn2" style="margin:0 3px 0 0;"><span><button type="button" onClick="addAlbum()">创建</button></span></span><span class="bt2"><span><button type="button" onClick="getObj('create_album_div').style.visibility='hidden'">取消</button></span></span></td>
		</tr>
	</table>      
		</div>
        </form>
	</div>
	<div class="tabsctn popUpcont" style="display:none">
		<div class="mb10">图片地址：<input id="networkImg" size="50" type="text" class="input" value="http://" /></div>
	</div>
	<div class="popBottom"><span class="btn2"><span><button type="button" onClick="insertImg()">插入图片</button></span></span></div>
</div>
<script type="text/javascript" src="js/core/core.js"></script>
<script type="text/javascript" src="js/global.js"></script>
<script type="text/javascript" src="js/pw_ajax.js"></script>
<script type="text/javascript" src="js/desktop/plugin.js"></script>
<script type="text/javascript" src="js/select.js"></script>
<script>
var imgpath = '$imgpath';
getObj('tabs').onmousedown=function(e){
	e = e||event;
	if(e.srcElement.id!='tabs')
		return;

	mouseRect = {x:e.clientX,y:e.clientY};
	document.onmousemove = dragging;
	document.onmouseup = drop;
};
function dragging(e){
	e = e||event;
	var box = parent.document.getElementById('pw_box');
	box.style.left = (e.clientX-mouseRect.x) + parseInt(box.style.left)+'px';
	box.style.top = (e.clientY-mouseRect.y) + parseInt(box.style.top)+'px';
}
function drop(e){
	document.onmousemove=null;
	document.onmouseup=null;
}
var cfg = {};
cfg.tabs = document.getElementById('tabs').getElementsByTagName('li');
cfg.container = getElementsByClassName('tabsctn',document.body);
cfg.callback = function(){
	window.frameElement.height = document.body.clientHeight+'px';
	if(!getObj("album_drop").getElementsByTagName("button").length);
};
PW.Tab(cfg);
PW.ClassBind(document.getElementById('album').getElementsByTagName('li'),'current','mousedown',function(e){
	(e.selected = !e.selected) || (e.className='');
});
function insertImg()
{
	if (parent.winduid == '') {
		parent.getObj('mainForm').verify.value = '$verifyhash';
	}
	var tabTitle = getElementsByClassName('current',getObj('tabs'))[0].title;
	switch(tabTitle)
	{
		case 'album':
			var ar = getElementsByClassName('current',getObj('album'));
			var l = ar.length;
			for (var i=0;i<l;i++)
			{
				parent.insertImageToPage(ar[i].getElementsByTagName('input')[0].value);
			}
			break;
		case 'local':
			var obj = getObj("uploadPhoto");
			obj.action = 'apps.php?q=photos&a=pweditor&verify='+parent.verifyhash + '&action=upload';
			ajax.send(obj.action,obj,
				function(){
					//alert(ajax.request.responseText);
					var rText = ajax.request.responseText.split('\t');
					parent.insertImageToPage(rText[1]);
				}
				);
			break;
		case 'network':
			var val = getObj('networkImg').value; 
			parent.insertImageToPage(val);
			break;
		default:
	}
}
function addAlbum() {
	var aname = getObj('albumName').value;
	
	
	if (IsElement('gdcode')){
		var gdcode = getObj('gdcode').value;
	}
	if (IsElement('qanswer')){
		var qanswer = getObj('qanswer').value;
	}
	if (IsElement('qkey')){
		var qkey = getObj('qkey').value;
	}
	if(IsElement('gdcode') && gdcode == ""){
		showDialog('error','请输入验证码',2);
		return false;
	}
	if (IsElement('qanswer') && qanswer == ""){
		showDialog('error','请输入问题答案',2);
		return false;
	}
	ajax.send('apps.php?q=photos&a=create&verify='+parent.verifyhash,'step=2&checkpwd=1&private=0&aname='+aname+'&gdcode=' + gdcode + '&qanswer=' + qanswer + '&qkey=' + qkey, function(){
		var rText = ajax.request.responseText.split('\t');
		if (rText[0] == 'success') {
			var albumList = getObj('album_list');
			albumList.options.add(new Option(aname,rText[1]),0);
			//getObj("album_drop").getElementsByTagName('button')[0].innerHTML = aname;
			albumList.value=rText[1];
			getObj('albumName').value='';
			getObj('create_album_div').style.visibility='hidden';
		} else if (rText[0] == 'limit_num') {
			if(navigator.userAgent.toLowerCase().indexOf('msie 6')>0){
				alert('您创建的相册已经达到'+rText[1]+'个');
			}
			else{
				showDialog('error','您创建的相册已经达到'+rText[1]+'个',2);
			}
		} else {
			if(navigator.userAgent.toLowerCase().indexOf('msie 6')>0){
				alert(rText[1] != '' ? rText[1] : '未知错误');
			}
			else{
			showDialog('error',rText[1] != '' ? rText[1] : '未知错误',2);
			}
		}
	});
}
function ajaxLoadPhotos(obj){
	var aid = obj.value;
	var albumHtml = '';
	ajax.send('apps.php?q=photos&a=pweditor&verify='+parent.verifyhash,'action=listphotos&private=0&aid='+aid, function(){
		var rText = ajax.request.responseText.split('\t');
		if (rText[0] == 'success') {
			try{var photos = JSONParse(rText[1]);
			if (typeof(photos)=='object') {
				for (var i in photos) {
					if (typeof(photos[i])=='object') {
						albumHtml += '<li><span></span><label><img data_src="'+ photos[i].thumbpath +'" width="56" height="56" /><input type="checkbox" value="' + photos[i].path + '" /></label></li>';
					}
				}
				getObj('album').innerHTML = albumHtml;
				getObj('photoList').style.display='';
				getObj('noPhotoList').style.display='none';
				
				PW.ClassBind(document.getElementById('album').getElementsByTagName('li'),'current','mousedown',function(e){(e.selected = !e.selected) || (e.className='');});
				lazyLoad();				
			}}catch(e){}
		}else{
			getObj('photoList').style.display='none';
			getObj('noPhotoList').style.display='';
		}
	});
}

//滚动图片延迟加载
	var scroller = getObj("photoList");
	var lazyLoad = function(){
		var li = scroller.getElementsByTagName("li");
		var clientHeight = scroller.clientHeight;
		var bottom = scroller.getBoundingClientRect().top + clientHeight;
		for(var i=0,j=li.length;i<j;i++)
		{
			var img = li[i].getElementsByTagName("img")[0];
			if(img.getBoundingClientRect().top<bottom && (img.src=="" ||!img.src))
			{
				img.src = img.getAttribute("data_src");
			}
		}
	}
	lazyLoad();
	scroller.onscroll = lazyLoad;
	if (parent.winduid == '') {
		window.frameElement.width = '452px';
		window.frameElement.height = document.body.clientHeight+'px';
	}
</script>
</body>
</html>
<!--
EOT;
?>-->